package com.xbongbong.pro.enums.datacenter.datawarning.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.enums.clazz.ConditionClass;
import com.xbongbong.pro.enums.smartsettings.enums.SmartSettingsConditionEnum;
import lombok.Getter;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @ClassName DataWarningConditionEnum
 * @Description 数据预警触发条件筛选条件枚举
 * @Author mengna.Deng
 * @Date 2021/4/15 14:22
 * @Version 1.0
 */
@Getter
public enum DataWarningConditionEnum {
    GREATEREQUAL("greaterequal", " >= ", "enum.dataWarningCondition.memo.greaterequal"),
    GREATERTHAN("greatethan", ">", "enum.dataWarningCondition.memo.greaterthan"),
    LESSEQUAL("lessequal", " <= ", "enum.dataWarningCondition.memo.lessequal"),
    LESSTHAN("lessthan", "<", "enum.dataWarningCondition.memo.lessthan"),
    RANGE("range", "between", "enum.dataWarningCondition.memo.range"),
    ;

    /**
     * 条件
     */
    private String symbol;

    /**
     * 将条件替换成符号
     */
    private String replaceSymbol;

    /**
     * 描述
     */
    private String memo;

    DataWarningConditionEnum(String symbol, String replaceSymbol, String memo){
        this.symbol = symbol;
        this.replaceSymbol = replaceSymbol;
        this.memo = memo;
    }

    public static DataWarningConditionEnum getBySymbol(String symbol) {
        for (DataWarningConditionEnum e : values()) {
            if (e.getSymbol().equals(symbol)) {
                return e;
            }
        }
        return null;
    }

    public String getMemo() {
        return I18nMessageUtil.getMessage(memo);
    }

    public static List<ConditionClass> getDataWarningConditonList() {
        List<ConditionClass> list = new ArrayList<ConditionClass>(){{
            new ArrayList(Arrays.asList(DataWarningConditionEnum.values())).forEach(item ->{
                ConditionClass conditionClass= new ConditionClass();
                BeanUtils.copyProperties(item, conditionClass);
                this.add(conditionClass);
            });
        }};
        return list;
    }
}
